package filters

import (
	"github.com/yjp211/web"

	"mutu/misc/conf"

	"mutu/service"
)

func loginRequire(ctx *web.Context) bool {
	ctx.Abort(403, "login require")
	return false
}

func NeedLogin(ctx *web.Context) bool {
	ck, err := ctx.Request.Cookie(conf.SessionKey)
	if err != nil {
		return loginRequire(ctx)
	}
	sesid := ck.Value
	ses, err := service.SessionService.QuerySession(sesid)
	if err != nil {
		return loginRequire(ctx)
	}
	ctx.Dict["session"] = ses

	return true
}
